package main

import (
	"github.com/gin-gonic/gin"
	"io"
	"net/http"
	"os"
)

func main() {
	//gin框架中间件使用【gin.Logger和gin.Recovery】
	//使用gin框架自带的中间件，将请求的日志记录到日志文件中
	log, _ := os.Create("gin.log")
	gin.DefaultWriter = io.MultiWriter(log)
	gin.DefaultErrorWriter = io.MultiWriter(log)

	r := gin.New()
	r.Use(gin.Logger(), gin.Recovery()) //Recovery防止程序出错挂掉
	r.GET("/test", func(c *gin.Context) {
		name := c.DefaultQuery("name", "dname")
		c.JSON(http.StatusOK, gin.H{
			"code": 200,
			"msg":  name,
		})
	})

	r.Run()
}
